﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GcmpCommandInterface.h"
#include "GbmpGuid.h"
#include "GcmpApiDeclaration.h"

namespace gcmp
{
    class ICommandPrevChecker;
    class ICommand;
    class CommandParameters;

    /// \brief 命令管理者
    ///
    class GCMP_COMMAND_INTERFACE_EXPORT ICommandManager
    {
    public:
        virtual ~ICommandManager(){}

        ///  \brief 获取命令管理者，单例
        ///
        /// \return
        static ICommandManager* Get();

        /// \brief 注册命令
        ///
        /// \param  moduleName 命令所在的模块名字
        /// \param  opCommand  命令
        /// \return 注册命令成功返回true,否则返回false。如果已经存在，返回false
        virtual bool RegisterCommand(const std::wstring & moduleName, OwnerPtr<ICommand> opCommand) = 0;

        ///  \brief 取消注册命令
        ///
        /// \param  opCommand  命令
        /// \return 取消注册命令成功返回true,否则返回false
        virtual bool UnRegisterCommand(const std::wstring &commandId) = 0;
        
        ///  \brief 获取命令
        ///
        /// \param  commandId  命令Id
        /// \return 指定Id的命令
        virtual ICommand* GetCommand(const std::wstring& commandId) const = 0;

        /// \brief 发送命令
        /// \param commandName   命令名称
        /// \param commandParams 命令参数
        /// \return 
        virtual void SendCommand(const std::wstring &commandName,const gcmp::CommandParameters &commandParams) const = 0;

        /// \brief 发送命令
        /// \param commandName    命令名称
        /// \return 
        virtual void SendCommand(const std::wstring &commandName) const = 0;

        /// \brief 发送命令,需要在日志中记录命令的额外参数时使用此接口，如打开文件命令
        /// \param commandName    命令名称
        /// \param hasCommandData 是否有额外参数
        /// \return 
        virtual void SendCommand(const std::wstring &commandName,bool hasCommandData) const = 0;

        /// \brief 设置命令执行前置检测回调
        /// \param opChecker 回调对象
        virtual void SetCommandPrevChecker(OwnerPtr<ICommandPrevChecker> opChecker) = 0;

        /// \brief 获取命令执行前置检测回调
        /// \return 回调对象
        virtual const ICommandPrevChecker* GetCommandPrevChecker() const = 0;
    };
}
